cbuffer MatrixBuffer : register(b0) // 256 byte
{
	float4x4 matViewProjection;
	float4x4 world;
	float4x4 view;
	float4x4 projection;
	float3 cameraPosition;
}

cbuffer Leaves : register(b13)//84 byte (96 byte)
{
	float4 TreePosition;
	float4x4 matTreeRotation;
	float scale;
}
#define worldUp cross(float3(-1,0,0),float3(0,0,-1))

struct VS_INPUT
{
	float4 Position : POSITION0;
	float2 Texcoord : TEXCOORD0;
	float3 Normal   : NORMAL0;
};

struct VS_INPUT_INST
{
	float4 Position :INSTANCE1;
	float4 mx       :INSTANCE2;
	float4 my       :INSTANCE3;
	float4 mz       :INSTANCE4;
	float4 mw       :INSTANCE5;
	float scale : INSTANCE6;
};

struct LEAVE_POS
{
	float4 position   :TEXCOORD1;
	float4 Color : COLOR0;
};

struct VertexOut
{
	float4 Position        : SV_POSITION;
	float2 TextureCoords   : TEXCOORD1;
	float4 Color           : COLOR0;
};

VertexOut vs_main(VS_INPUT input, LEAVE_POS leavesPos)
{
	VertexOut Out = (VertexOut)0;

	input.Position.xyz = mul(input.Position.xyz * 1.0f, scale); // Scales the vertex of the leave.
	float4 finPos = mul(leavesPos.position, matTreeRotation); // Rotate the leave position.
		finPos = mul(finPos, scale); // Scales the leave position.
	finPos = float4(TreePosition.xyz * 2.0f + finPos.xyz, 1); // Adds the tree trunk position.
	finPos = input.Position + mul(finPos, view); // transform to world view

	Out.Position = mul(finPos + float4(view[3].xyz, 0), projection); // transform to world view projection.
	Out.TextureCoords.x = input.Texcoord.x; // texture coordinates.
	Out.TextureCoords.y = input.Texcoord.y; // texture coordinates.

	return Out;
}
